<template>
	<scroll-view>
		<view class="cu-list menu">
			<view class="cu-item">
				<input placeholder="资源名称" name="input" v-model="resName" class="content"></input>
			<button class="cu-btn light bg-blue cuIcon margin-left-xs" @tap="shareList()">
				<text class="cuIcon-search"></text>
			</button>
			</view>
		</view>
		<view class="cu-list menu">
			<view class="cu-item" v-for="(item, index) in resInfo" :key="index" @click="openRes(index)">
				<view class="text-left">
					<view class="text-grey">{{item.RES_NAME_}}</view>
				</view>
			</view>
		</view>
	</scroll-view>
</template>

<script>
	export default {
		data() {
			return {
				resName: '',
				resInfo: []
			}
		},
		methods: {
			openRes(index){
				let that = this;
				uni.navigateTo({
					url: '../share/share?from=search&id=' + that.resInfo[index].RES_ID_
				});
			},
			shareList(){
				let that = this;
				uni.request({
					url: that.baseUrl + "/shareSearch",
					data: {
						resName: that.resName
					},
					success(res) {
						if (res.statusCode == 200) {
							if(res.data.length == 0){
								uni.showToast({
									icon: 'none',
									title: '未搜索到相关资源！',
									duration: 1200
								});
								that.resInfo = [];
							}else{
								that.resInfo = res.data;
							}
						} else {
							uni.showToast({
								icon: 'none',
								title: '获取资源失败，请重试！',
								duration: 1200
							});
						}
					},
					fail(res) {
						uni.showToast({
							icon: 'none',
							title: '服务器开了小差，请稍后再试！',
							duration: 1200
						});
					}
				});
			}
		}
	}
</script>

<style>

</style>
